import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import vueAxios from "vue-axios";
import axios from "axios";
import Router from "./router/index";
import "lib-flexible";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "../src/assets/css/common.css";
import "../src/assets/fonts/fonts.css";
import VueClipboard from "vue-clipboard2";
import WebSocket from "./webSocket/webSocket";
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'

require('@/assets/gt/gt.js');
import {
    provinceAndCityData,
    regionData,
    provinceAndCityDataPlus,
    regionDataPlus,
    CodeToText,
    TextToCode,
} from "element-china-area-data";
import { fetch, post } from "./api/http";
import VueDirectiveImagePreviewer from "vue-directive-image-previewer";
import "vue-directive-image-previewer/dist/assets/style.css";
Vue.prototype.$initGeet = initGeetest;
Vue.prototype.WebSocket = WebSocket;
Vue.prototype.$fetch = fetch;
Vue.prototype.$post = post;
Vue.use(Viewer);
Vue.use(ElementUI);
Vue.use(VueDirectiveImagePreviewer);
Vue.use(vueAxios, axios);
Vue.use(VueClipboard);
Vue.config.productionTip = false;
Vue.prototype.getRem = getRem;
Vue.prototype.delNum = delNum;
Vue.prototype.delList = delList;
Vue.prototype.navigate = navigate;
Vue.prototype.defaultInfor = defaultInfor;
Vue.prototype.isToken = isToken;
Vue.prototype.tourist = tourist;
Vue.prototype.isConcern = isConcern;
Viewer.setDefaults({
    defaultOptions: {
       zIndex: 9999
     },
     Options: {
       "inline": true,
       "button": true,
       "navbar": true,
       "title": true,
       "toolbar": true,
       "tooltip": true,
       "movable": true,
       "zoomable": true,
       "transition": true,
       "fullscreen": true,
       "keyboard": true,
       "url": "data-source"
     }
   })
new Vue({
    router: Router,
    store,
    render: (h) => h(App),
    mounted() {
        document.dispatchEvent(new Event("render-event"));
    },
}).$mount("#app");
router.beforeEach((to, from, next) => {
    //路由发生改变修改页面title
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    next();
});
export function getRem(pwidth, prem) {
    var html = document.getElementsByTagName("html")[0];
    var oWidth =
        document.body.clientWidth || document.documentElement.clientWidth;
    // 页面宽度>1290时才会自适应
    //<1220 宽度定死
    if (oWidth > 1220) {
        html.style.fontSize = (oWidth / pwidth) * prem + "px";
    }
}
export function delNum(num) {
    let int = Math.round(num * 100) / 100;
    let str = int.toString();
    if (str.indexOf(".") < 0) {
        str = str + ".";
    }
    while (str.length <= str.indexOf(".") + 2) {
        str = str + "0";
    }
    return str;
}

// 定义列表为空的处理
export function delList(response, listName) {
    this.$set(response, "listShow", true);
    if (response[listName].length == 0) {
        this.$set(response, "listShow", false);
    }
}
//定义跳转页面传参
export function navigate(path, id) {
    this.$router.push({
        path: `${path}`,
        query: { id: id },
    });
}
//定义默认信息处理
export function defaultInfor(objName, name, newVal) {
    if (objName[name] == null) {
        objName[name] = newVal;
    }
}
// //检查是否有token
export function isToken() {
    if (localStorage.getItem("token") != null) {
        return true;
    } else {
        return false;
    }
}
//处理游客状态
export function tourist() {
    if (localStorage.getItem("token") == null) {
        this.$message.error("亲亲请先成为用户哦");
        return false;
    }
    return true;
}
//处理自己关注自己
export function isConcern(authorId) {
    let userId = JSON.parse(localStorage.getItem("user")).id;
    if (authorId === userId) {
        this.$message.error("亲亲自己不能关注自己哦");
        return false;
    } else {
        return true;
    }
}